package com.cabbagetofu.crowd.controller;


import com.atguigu.crowd.until.ResultEntity;
import com.cabbagetofu.crowd.entity.vo.AddressVO;
import com.cabbagetofu.crowd.entity.vo.OrderProjectVO;
import com.cabbagetofu.crowd.entity.vo.OrderVO;
import com.cabbagetofu.crowd.mapper.AddressPOMapper;
import com.cabbagetofu.crowd.mapper.OrderPOMapper;
import com.cabbagetofu.crowd.mapper.OrderProjectPOMapper;
import com.cabbagetofu.crowd.service.api.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderProviderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/save/orderVO/remote")
    ResultEntity<String> saveOrderRemote(@RequestBody OrderVO orderVO){

        try {

            orderService.saveOrder(orderVO);
            return ResultEntity.successWithoutData();
        } catch (Exception e) {

            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/save/address/remote")
    public ResultEntity<String> saveAddressRemote(@RequestBody AddressVO addressVO){

        try {

            orderService.saveAddress(addressVO);
            return ResultEntity.successWithoutData();
        } catch (Exception e) {

            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/addressVO/remote")
    public ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId){

        try {

            List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);
            return ResultEntity.successWithData(addressVOList);
        } catch (Exception e) {

            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/order/projectVO/retmote")
    public ResultEntity<OrderProjectVO> getOrderProjectVORemote(@RequestParam("returnId") Integer returnId){

        try {

            OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(returnId);
            return ResultEntity.successWithData(orderProjectVO);
        } catch (Exception e) {

            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }


    }

}
